package com.bw.mallshop.timmer;

import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;

import com.bw.mallshop.mvvm.viewmodel.SplashViewModel;

import java.lang.ref.WeakReference;

/**
 * @author KK
 * @description:
 * @date :2021/10/13 16:19
 */
public class TimeHandler extends Handler {

    private WeakReference<SplashViewModel>weakReference;
    private int index = 3;
    public TimeHandler(SplashViewModel viewModel){
        weakReference = new WeakReference<>(viewModel);
    }
    @Override
    public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        if(weakReference==null){
            return;
        }
        if(weakReference.get()==null){
            return;
        }
        if(msg.what==0){
            index--;
            weakReference.get().timeObserable.set(""+index+"S");

        }else {
            weakReference.get().skipTimer();
        }

    }
}
